<!--#include file="../nav/admin_top.php" -->
<!--#include file="../nav_menu/admin_ku_js.php" -->
<div class="titleDiv">
	<div class="titleCaption">
		<span class="captionSpan">菜品库存 - 会服填写</span>
	</div>
</div>
<div  class="button_div">
	<button onclick="fnSave()">保 存</button>
	或 
	<button onclick="fnReturn()">返 回</button>
</div>

<script type="text/javascript">
$().ready(function(){
	Calendar.setup({
		inputField:'plandate',
		button:'slt_plandate',
		ifFormat:"%Y-%m-%d",
		showsTime:false
	});
 
});
</script>


<!--比较通用-->
<form id="myform" action="" method="post" onsubmit="return false;">
<div class="blockdiv">
	<div class="titlediv">库存批次信息</div>
	<table class="mytable" > 
		<tr>	
			<td class="mylabel"> 库存批次标识：</td>
			<td class="myinfo" style="color:#333333;font-size:14px;" >
				<input type="text" class="textBox" id="name" name="name" value="{$rs.name}" maxlength="100" style="text-align:left;width:140px"  />
				
			</td>
			<td class="mylabel">计划到货日期：</td>
			<td class="myinfo" style="color:#FF3333;font-size:14px;" > 
				
				<input type="text" class="textBox" id="plandate" name="plandate" value="{$rs.plandate}"   style="width:70px"  readonly="readonly" />
				<input type="button" class="btnicon_calendar" id="slt_plandate" />
			</td> 	
			<td class="mylabel">实际到货日期：</td>
			<td class="myinfo" style="color:#FF3333;font-size:14px;" >
				<input type="text" class="textBoxOff" name="acdate" id="acdate" value="{$rs.acdate}" readonly="readonly"  style="width:120px"  />
			</td> 		
		</tr>  
	</table> 
</div>
</form>
<div class="sourcetb_out" >
	<div style="width:<?PHP echo 3600+( count($rs_ku_index) * 750	) ?>px;">
		<table class="sourcetb" id="sourcetb">
			<tbody>
				<tr>
					<th colspan="6">会服计划</th>
					<th colspan="4">采购</th>
					<th colspan="6">发货</th>
					<th colspan="4">工厂</th>
					<th colspan="9">第 1 次加工
						<div class="right">
							<a href="javascript:void(0)" onclick="fnNewChu(0)">添加订单与出库</a> 
						</div>
					</th>
					<?PHP
					$jia_indexs = 2;
					$chu_indexs = 1;
					foreach($rs_ku_index as $v){
						if($v['type'] == 'chu'){
							echo '
							<th colspan="5">第 '.$chu_indexs.' 次订单与出库
								<div class="right">
									<a href="javascript:void(0)" onclick="fnNewChu('.$v['id'].')">添加订单与出库</a> 
									<a href="javascript:void(0)" onclick="fnDelChu('.$v['id'].','.$chu_indexs.')">删除</a>
								</div>
							</th>';
							$chu_indexs++;
						}else{
							echo '
							<th colspan="9">第 '.$jia_indexs.' 次加工
								<div class="right">
									<a href="javascript:void(0)" onclick="fnNewChu('.$v['id'].')">添加订单与出库</a> 
								</div>
							</th>';
							$jia_indexs++;
						}
					}
					?>
					<th colspan="4">&nbsp;</th>
				</tr>
			</tbody>
			<tbody>
				<tr>
					<th style="40px">序号</th>
					<th style="70px">品类</th>
					<th style="70px">菜品编码</th>
					<th style="130px">菜品名称</th>
					<th style="130px">
						供应计划<br />(KG) 
					</th>
					<th style="200px">
						备注
					</th>
					
					
					<th style="130px">采购重量<br />(KG) 
					</th>
					<th style="130px">采购单价<br />(元/KG) 
					</th>
					<th style="130px">采购金额<br />(元) 
					</th>
					<th style="200px">备注 
					</th>
					
					<th style="130px">发货重量<br />(KG) 
					</th>
					<th style="130px">发货件数<br />(件) 
					</th> 
					<th style="130px">发货金额<br />(元) 
					</th>
					<th style="130px">云贵次品<br />(KG) 
					</th>
					<th style="130px">次品金额<br />(元) 
					</th>
					<th style="200px">备注 
					</th>
					
					
					
					<th style="130px">到货重量<br />(KG) 
					</th>
					<th style="130px">到货件数<br />(件) 
					</th>
					<th style="130px">来料损耗<br />(KG) 
					</th>
					<th style="200px">备注 
					</th>
					
					<th style="130px">库存原料<br />(KG)</th>
					<th style="130px">库存袋装<br />(份)</th>
					<th style="130px">袋装损耗<br />(份)</th>
					<th style="130px">原料损耗<br />(KG)</th>
					<th style="130px">加工原料<br />(KG)</th>
					<th style="130px">生产袋装<br />(份)</th>
					<th style="130px">实际平均<br />规格(KG/份)</th>
					<th style="130px">加工后总原<br />料(KG)</th>
					<th style="130px">加工后总袋<br />装(份)</th>
					<?PHP
					$jia_indexs = 2;
					$chu_indexs = 1;
					foreach($rs_ku_index as $v){
						if($v['type'] == 'chu'){
							echo '
					<th>计划订单<br />(份)
						<br><button class="autobtn" onclick="fnAutoOrder('.$chu_indexs.')">自动</button> 
					</th>
					<th>实际出库<br />(份) 
					</th>
					<th>出库重量<br />(KG)</th>
					<th>库存原料<br />(KG)</th>
					<th>库存袋装<br />(份)</th>
							';
							$chu_indexs++;
						}else{
							echo '
					<th style="130px">库存原料<br />(KG)</th>
					<th style="130px">库存袋装<br />(份)</th>
					<th style="130px">袋装损耗<br />(份)</th>
					<th style="130px">原料损耗<br />(KG)</th>
					<th style="130px">加工原料<br />(KG)</th>
					<th style="130px">生产袋装<br />(份)</th>
					<th style="130px">实际平均<br />规格(KG/份)</th>
					<th style="130px">加工后总原<br />料(KG)</th>
					<th style="130px">加工后总袋<br />装(份)</th>
							';
							$jia_indexs++;
						}
					}
					?>
					<th style="">成品报废<br />(KG)</th>
					<th style="">实际剩余原料<br />(KG)</th>
					<th style="">实际剩余袋装<br />(份)</th>
					<th style="">备注  </th>
				</tr>
			</tbody> 
			<tbody id="veges_tr"> 
			<?PHP
			$k=1;
			foreach($rs_ku_vege as $key=>$val){
				echo '<tr id="tr_'.$k.'" index="'.$k.'" class="tr_source"  vege_id="'.$val['vege_id'].'" >';
				echo '	<td >'.$k.'</td>';
				echo '	<td >'.'<input type="text" class="textBoxOff" readonly="readonly" value="'.$val['vege_typename'].'" />'.'</td>'; 
				echo '	<td >'.'<input type="text" class="textBoxOff" readonly="readonly" value="'.$val['vege_code'].'" />'.'</td>'; 
				echo '	<td >'.'<input type="text" class="textBoxOff" readonly="readonly" value="'.$val['vege_name'].'" />'.'</td>';  
				echo '	<td >';
				echo '		<input type="text" class="textBox  " id="plan_weight_'.$k.'" maxlength="50" value="'.$val['plan_weight'].'" />';
				echo '	</td>';
				echo '	<td >';
				echo '		<input type="text" class="textBox textRemark" id="plan_remark_'.$k.'"  maxlength="255" value="'.$val['plan_remark'].'" />';
				echo '	</td>';
				
				
				echo '	<td >';
				echo '		<input type="text"  class="textBoxOff" readonly="readonly" id="cg_weight_'.$k.'"  maxlength="50" value="'.$val['cg_weight'].'" />';
				echo '	</td>';
				echo '	<td >';
				echo '		<input type="text"  class="textBoxOff" readonly="readonly" id="cg_price_'.$k.'"  maxlength="50" value="'.$val['cg_price'].'" />';
				echo '	</td>';
				echo '	<td >';
				echo '		<input type="text" class="textBoxOff" readonly="readonly"  id="cg_total_'.$k.'"  maxlength="50" value="0" />';
				echo '	</td>';
				echo '	<td >';
				echo '		<input type="text" class="textBoxOff textRemark "  readonly="readonly" id="cg_remark_'.$k.'"  maxlength="255" value="'.$val['cg_remark'].'" />';
				echo '	</td>';
				
				
				
				echo '	<td >';
				echo '		<input type="text" class="textBoxOff" readonly="readonly" id="send_weight_'.$k.'"  maxlength="50" value="'.$val['send_weight'].'" />';
				echo '	</td>';
				echo '	<td >';
				echo '		<input type="text" class="textBoxOff" readonly="readonly" id="send_nums_'.$k.'"  maxlength="50" value="'.$val['send_nums'].'" />';
				echo '	</td>';
				echo '	<td >';
				echo '		<input type="text" class="textBoxOff" readonly="readonly"  id="send_total_'.$k.'"  maxlength="50" value="0" />';
				echo '	</td>';
				echo '	<td >';
				echo '		<input type="text" class="textBoxOff" readonly="readonly"  id="yg_weight_'.$k.'"  maxlength="50" value="0" />';
				echo '	</td>';
				echo '	<td >';
				echo '		<input type="text" class="textBoxOff" readonly="readonly"  id="yg_total_'.$k.'"  maxlength="50" value="0" />';
				echo '	</td>';
				echo '	<td >';
				echo '		<input type="text" class="textBoxOff textRemark "  readonly="readonly"  id="send_remark_'.$k.'"  maxlength="255" value="'.$val['send_remark'].'" />';
				echo '	</td>';
				
				
				echo '	<td >';
				echo '		<input type="text" class="textBoxOff" readonly="readonly" id="gcall_weight_'.$k.'"  maxlength="50" value="'.$val['gcall_weight'].'" />';
				echo '	</td>';
				echo '	<td >';
				echo '		<input type="text" class="textBoxOff" readonly="readonly" id="gcall_nums_'.$k.'"  maxlength="50" value="'.$val['gcall_nums'].'" />';
				echo '	</td>';
				echo '	<td >';
				echo '		<input type="text" class="textBoxOff" readonly="readonly" id="gcloss_weight_'.$k.'"  maxlength="50" value="'.$val['gcloss_weight'].'" />';
				echo '	</td>';
				echo '	<td >';
				echo '		<input type="text"  class="textBoxOff textRemark "  readonly="readonly"  id="gc_remark_'.$k.'"  maxlength="255" value="'.$val['gc_remark'].'" />';
				echo '	</td>';
				
				
				echo '	<td >';
				echo '		<input type="text" class="textBoxOff" readonly="readonly"  id="fst_kcyl_weight_'.$k.'"  maxlength="50" value="0" />';
				echo '	</td>';
				echo '	<td >';
				echo '		<input type="text" class="textBoxOff" readonly="readonly"  id="fst_kcdz_nums_'.$k.'"  maxlength="50" value="0" />';
				echo '	</td>';
				echo '	<td >';
				echo '		<input type="text" class="textBoxOff" readonly="readonly"  id="fst_packloss_nums_'.$k.'"  maxlength="50" value="'.$val['fst_packloss_nums'].'" />';
				echo '	</td>';
				echo '	<td >';
				echo '		<input type="text"  class="textBoxOff" readonly="readonly"  id="fst_mateloss_weight_'.$k.'"  maxlength="50" value="'.$val['fst_mateloss_weight'].'" />';
				echo '	</td>';
				echo '	<td >';
				echo '		<input type="text"  class="textBoxOff" readonly="readonly"  id="fst_matemake_weight_'.$k.'"  maxlength="50" value="'.$val['fst_matemake_weight'].'" />';
				echo '	</td>';
				echo '	<td >';
				echo '		<input type="text"  class="textBoxOff" readonly="readonly"  id="fst_packmake_nums_'.$k.'"  maxlength="50" value="'.$val['fst_packmake_nums'].'" />';
				echo '	</td>';
				echo '	<td >';
				echo '		<input type="text" class="textBoxOff" readonly="readonly"  id="fst_pack_'.$k.'"  maxlength="50" value="0" />';
				echo '	</td>';
				echo '	<td >';
				echo '		<input type="text" class="textBoxOff" readonly="readonly"  id="fst_jgh_weight_'.$k.'"  maxlength="50" value="0" />';
				echo '	</td>';
				echo '	<td >';
				echo '		<input type="text" class="textBoxOff" readonly="readonly"  id="fst_jgh_nums_'.$k.'"  maxlength="50" value="0" />';
				echo '	</td>';
				
				
				 
				 
				$jia_indexs = 2;
				$chu_indexs = 1;
				foreach($rs_ku_index as $v){
					if($v['type'] == 'chu'){
						if(!isset($v['veges'][$key])){
							$i_obj = array();
						}else{
							$i_obj = $v['veges'][$key];
						}
						echo '	<td >';
						echo '		<input type="text" class="textBox  " id="orderout_nums_'.$k.'_'.$chu_indexs.'"  maxlength="50" value="'.$i_obj['orderout_nums'].'" />';
						echo '	</td>';
						echo '	<td >';
						echo '		<input type="text"  class="textBoxOff" readonly="readonly"  id="actout_nums_'.$k.'_'.$chu_indexs.'"  maxlength="50" value="'.$i_obj['actout_nums'].'" />';
						echo '	</td>';
						
						echo '	<td >';
						echo '		<input type="text"   class="textBoxOff" readonly="readonly"  id="actout_kg_'.$k.'_'.$chu_indexs.'"  maxlength="50" value="0" />';
						echo '	</td>';
						echo '	<td >';
						echo '		<input type="text"   class="textBoxOff" readonly="readonly"  id="out_kcyl_'.$k.'_'.$chu_indexs.'"  maxlength="50" value="0" />';
						echo '	</td>';
						echo '	<td >';
						echo '		<input type="text"    class="textBoxOff" readonly="readonly"  id="out_kcdz_'.$k.'_'.$chu_indexs.'"  maxlength="50" value="0" />';
						echo '	</td>';
						$chu_indexs++;
					}else{
						if(!isset($v['veges'][$key])){
							$i_obj = array();
						}else{
							$i_obj = $v['veges'][$key];
						}
						echo '	<td >';
						echo '		<input type="text" class="textBoxOff" readonly="readonly"  id="kcyl_weight_'.$k.'_'.$jia_indexs.'"  maxlength="50" value="0" />';
						echo '	</td>';
						echo '	<td >';
						echo '		<input type="text" class="textBoxOff" readonly="readonly"  id="kcdz_nums_'.$k.'_'.$jia_indexs.'"  maxlength="50" value="0" />';
						echo '	</td>';
						echo '	<td >';
						echo '		<input type="text" class="textBoxOff" readonly="readonly" id="packloss_nums_'.$k.'_'.$jia_indexs.'"  maxlength="50" value="'.$i_obj['packloss_nums'].'" />';
						echo '	</td>';
						echo '	<td >';
						echo '		<input type="text" class="textBoxOff" readonly="readonly" id="mateloss_weight_'.$k.'_'.$jia_indexs.'"  maxlength="50" value="'.$i_obj['mateloss_weight'].'" />';
						echo '	</td>';
						echo '	<td >';
						echo '		<input type="text" class="textBoxOff" readonly="readonly" id="matemake_weight_'.$k.'_'.$jia_indexs.'"  maxlength="50" value="'.$i_obj['matemake_weight'].'" />';
						echo '	</td>';
						echo '	<td >';
						echo '		<input type="text" class="textBoxOff" readonly="readonly" id="packmake_nums_'.$k.'_'.$jia_indexs.'"  maxlength="50" value="'.$i_obj['packmake_nums'].'" />';
						echo '	</td>';
						echo '	<td >';
						echo '		<input type="text" class="textBoxOff" readonly="readonly"  id="pack_'.$k.'_'.$jia_indexs.'"  maxlength="50" value="0" />';
						echo '	</td>';
						echo '	<td >';
						echo '		<input type="text" class="textBoxOff" readonly="readonly"  id="jgh_weight_'.$k.'_'.$jia_indexs.'"  maxlength="50" value="0" />';
						echo '	</td>';
						echo '	<td >';
						echo '		<input type="text" class="textBoxOff" readonly="readonly"  id="jgh_nums_'.$k.'_'.$jia_indexs.'"  maxlength="50" value="0" />';
						echo '	</td>';
						
						$jia_indexs++;
					}
				}
				 
				
				echo '	<td >';
				echo '		<input type="text" class="textBoxOff" readonly="readonly"  id="bf_weight_'.$k.'"  maxlength="50" value="'.$val['bf_weight'].'" />';
				echo '	</td>';
				echo '	<td >';
				echo '		<input type="text"   class="textBoxOff" readonly="readonly"  id="end_weight_'.$k.'"  maxlength="50" value="0" />';
				echo '	</td>';
				echo '	<td >';
				echo '		<input type="text"   class="textBoxOff" readonly="readonly"  id="end_nums_'.$k.'"  maxlength="50" value="0" />';
				echo '	</td>';
				echo '	<td >';
				echo '		<input type="text" class="textBoxOff textRemark" readonly="readonly" id="remark_'.$k.'"  maxlength="50" value="'.$val['remark'].'" />';
				echo '	</td>';
				echo '</tr>';
				 
				$k++;
			}
			?>
			</tbody>
		</table>
	</div>
</div>



<script type="text/javascript">
var g_vegetype = {json_encode($g_vegetype)};
function fnVegeChange(){
	var vege_type_id = $('#vege_type_id').val();
	if(vege_type_id == ''){
		$('#vege_id').html('<option value="">--请选择类别--</option>');
		return false;
	}
	var obj = g_vegetype[vege_type_id];
	var htmls = '';
	for(i=0; i<obj['veges'].length; i++){
		htmls += '<option value="'+obj['veges'][i].id+'">('+obj['veges'][i].code+')'+obj['veges'][i].name+'</option>';
	}
	$('#vege_id').html(htmls);	
}
function fnVegeSave(){
	var vege_id = $('#vege_id').val();
	if(vege_id != ''){
		$('button').attr('disabled','disabled');
		$.post(
			'/admin_ku/addvege_save',
			{
				ku_id:rs.id,
				vege_id:vege_id
			},
			function(e){
				$('button').attr('disabled','');
				var ok = errorHandler(e);
				if(ok){　 
					window.location.reload();
				}
			}
		);
	}else{
		alert('请选择菜品');
	}
}
</script>
<div class="blockdiv">
	<div class="titlediv">向本次批次中添加菜品</div>
	<a onclick="$('#addvege').show()" href="javascript:void(0)">选择添加菜品</a>
	<div class="margin10" id="addvege" style="display:none">
		 <select id="vege_type_id" onchange="fnVegeChange()">
		 	<option value="">--请选择类别--</option>
			<?PHP
			foreach($g_vegetype as $v){
				echo '<option value="'.$v['id'].'">'.$v['type_name'].'</option>';
			}
			?>
		 </select>
		 <select id="vege_id">
		 	<option value="">--请选择类别--</option>
		 </select>
		 <button onclick="fnVegeSave()">添加</button>
	</div>
		
</div>


<div  class="button_div">
	<button onclick="fnSave()">保 存</button>
	或 
	<button onclick="fnReturn()">返 回</button>
</div>












<script type="text/javascript">
/* 保存 */
function fnSave(){
	//批次信息
	var forms = {
		id:rs.id,
		name:$('#name').val(),
		plandate:$('#plandate').val()
	};
	
	
	//蔬菜信息
	var forms_vege = [];
	for(var k=1; k<=rs_ku_veges.length; k++ ){
		var obj = rs_ku_veges[k-1];
		forms_vege.push({
			ku_id:rs.id,
			vege_id:obj.vege_id,
			plan_weight:$('#plan_weight_'+k).val(),
			plan_remark:$('#plan_remark_'+k).val()
		});
	}
	
	//出库信息保存
	var forms_chu = [];
	for(var i=1; i<=rs_ku_index.length; i++ ){
		var obj = rs_ku_index[i-1];
		if(obj.type != 'chu'){
			continue;
		}
		for(var k=1; k<=rs_ku_veges.length; k++ ){
			var kobj = rs_ku_veges[k-1];
			forms_chu.push({
				ku_index_id:obj.id,
				vege_id:kobj.vege_id,
				orderout_nums:$('#orderout_nums_'+k+'_'+i).val()
			});
		}
	}
	
	
  $('button').attr('disabled','disabled');
	$.post(
		'/admin_ku/plan_save',
		{
			forms:JSON.encode(forms), 
			forms_vege:JSON.encode(forms_vege) , 
			forms_chu:JSON.encode(forms_chu) 
		},
		function(e){
  		$('button').attr('disabled','');
			var ok = errorHandler(e);
			if(ok){　 
				window.location.reload();
			}
		}
	);
}
</script>
<!--#include file="../nav/admin_bottom.php" -->